{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  读取数据\n",
    "def readData(num):\n",
    "    data = pd.read_csv(\"D:/机器学习/野火/区块/区块\"+ str(num) + \".csv\")\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  批量读取dataframe\n",
    "for i in range(1, 14):\n",
    "    exec(\"data\" + str(i) + \"= readData(\" + str(i) + \")\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>acq_date</th>\n",
       "      <th>frp/MW</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-36.46985</td>\n",
       "      <td>141.06317</td>\n",
       "      <td>2019/10/2</td>\n",
       "      <td>4.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>-36.46885</td>\n",
       "      <td>141.06352</td>\n",
       "      <td>2019/10/2</td>\n",
       "      <td>3.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-36.46086</td>\n",
       "      <td>141.10703</td>\n",
       "      <td>2019/10/1</td>\n",
       "      <td>4.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-36.36138</td>\n",
       "      <td>141.12328</td>\n",
       "      <td>2019/10/14</td>\n",
       "      <td>2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>-37.23269</td>\n",
       "      <td>141.12428</td>\n",
       "      <td>2019/10/22</td>\n",
       "      <td>36.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2079</th>\n",
       "      <td>-37.33434</td>\n",
       "      <td>142.49785</td>\n",
       "      <td>2019/12/23</td>\n",
       "      <td>3.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2080</th>\n",
       "      <td>-37.33282</td>\n",
       "      <td>142.49815</td>\n",
       "      <td>2019/12/22</td>\n",
       "      <td>6.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2081</th>\n",
       "      <td>-37.32859</td>\n",
       "      <td>142.49823</td>\n",
       "      <td>2019/12/22</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2082</th>\n",
       "      <td>-37.33557</td>\n",
       "      <td>142.49849</td>\n",
       "      <td>2019/12/21</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2083</th>\n",
       "      <td>-37.33487</td>\n",
       "      <td>142.49940</td>\n",
       "      <td>2019/12/22</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2084 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      latitude  longitude    acq_date  frp/MW\n",
       "0    -36.46985  141.06317   2019/10/2     4.9\n",
       "1    -36.46885  141.06352   2019/10/2     3.7\n",
       "2    -36.46086  141.10703   2019/10/1     4.2\n",
       "3    -36.36138  141.12328  2019/10/14     2.1\n",
       "4    -37.23269  141.12428  2019/10/22    36.7\n",
       "...        ...        ...         ...     ...\n",
       "2079 -37.33434  142.49785  2019/12/23     3.9\n",
       "2080 -37.33282  142.49815  2019/12/22     6.2\n",
       "2081 -37.32859  142.49823  2019/12/22     1.0\n",
       "2082 -37.33557  142.49849  2019/12/21     0.5\n",
       "2083 -37.33487  142.49940  2019/12/22     1.0\n",
       "\n",
       "[2084 rows x 4 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #  整合相同时间段的数据\n",
    "# days_list = list(data1['acq_date'])\n",
    "# position = []\n",
    "# for index in days_list:\n",
    "#     address_index = [x for x in range(len(days_list)) if days_list[x] == index]\n",
    "#     position.append([index, address_index])\n",
    "\n",
    "# dict_address = dict(position)\n",
    "\n",
    "# #  着火点数量\n",
    "# print(len(dict_address['2019/10/2']))\n",
    "\n",
    "# #  着火点的dataframe的索引\n",
    "# print(dict_address['2019/10/2'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ave_frp(dataframe, day):\n",
    "    days_list = list(dataframe['acq_date'])\n",
    "    position = []\n",
    "    for index in days_list:\n",
    "        address_index = [x for x in range(len(days_list)) if days_list[x] == index]\n",
    "        position.append([index, address_index])\n",
    "\n",
    "    dict_address = dict(position)\n",
    "\n",
    "    #  着火点数量\n",
    "#     print(len(dict_address[day]))\n",
    "\n",
    "    #  着火点的dataframe的索引\n",
    "#     print(dict_address[day])\n",
    "    \n",
    "    #  计算frp在某一天内的平均值\n",
    "    ave_list = []\n",
    "    for ave in dict_address[day]:\n",
    "        ave_list.append(dataframe.iloc[ave,:][\"frp/MW\"])\n",
    "\n",
    "    #  返回平均值与着火点数量\n",
    "    ave_frp_num = np.mean(ave_list)\n",
    "    return ave_frp_num, len(dict_address[day])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23.116666666666667 30\n"
     ]
    }
   ],
   "source": [
    "#  验证\n",
    "num, day = ave_frp(data1, '2019/10/2')\n",
    "print(num, day)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2019/10/1\n",
      "8.968421052631578 19\n",
      "2019/10/2\n",
      "23.116666666666667 30\n",
      "2019/10/3\n",
      "14.616666666666669 12\n",
      "2019/10/4\n",
      "1.2999999999999998 4\n",
      "2019/10/5\n",
      "2.4 1\n",
      "这天不存在着火点: 2019/10/6\n",
      "这天不存在着火点: 2019/10/7\n",
      "这天不存在着火点: 2019/10/8\n",
      "这天不存在着火点: 2019/10/9\n",
      "2019/10/10\n",
      "5.5 1\n",
      "这天不存在着火点: 2019/10/11\n",
      "这天不存在着火点: 2019/10/12\n",
      "这天不存在着火点: 2019/10/13\n",
      "2019/10/14\n",
      "2.1 2\n",
      "2019/10/15\n",
      "18.4 1\n",
      "2019/10/16\n",
      "12.05 2\n",
      "这天不存在着火点: 2019/10/17\n",
      "这天不存在着火点: 2019/10/18\n",
      "这天不存在着火点: 2019/10/19\n",
      "这天不存在着火点: 2019/10/20\n",
      "2019/10/21\n",
      "5.766666666666667 3\n",
      "2019/10/22\n",
      "18.116666666666667 6\n",
      "2019/10/23\n",
      "0.4 2\n",
      "这天不存在着火点: 2019/10/24\n",
      "2019/10/25\n",
      "4.4 1\n",
      "2019/10/26\n",
      "4.7 1\n",
      "这天不存在着火点: 2019/10/27\n",
      "2019/10/28\n",
      "6.510526315789474 19\n",
      "2019/10/29\n",
      "6.116666666666667 6\n",
      "这天不存在着火点: 2019/10/30\n",
      "这天不存在着火点: 2019/10/31\n",
      "这天不存在着火点: 2019/11/1\n",
      "2019/11/2\n",
      "0.4 1\n",
      "这天不存在着火点: 2019/11/3\n",
      "这天不存在着火点: 2019/11/4\n",
      "这天不存在着火点: 2019/11/5\n",
      "这天不存在着火点: 2019/11/6\n",
      "这天不存在着火点: 2019/11/7\n",
      "这天不存在着火点: 2019/11/8\n",
      "这天不存在着火点: 2019/11/9\n",
      "2019/11/10\n",
      "1.2 1\n",
      "2019/11/11\n",
      "16.3 1\n",
      "这天不存在着火点: 2019/11/12\n",
      "这天不存在着火点: 2019/11/13\n",
      "这天不存在着火点: 2019/11/14\n",
      "这天不存在着火点: 2019/11/15\n",
      "这天不存在着火点: 2019/11/16\n",
      "2019/11/17\n",
      "9.9 3\n",
      "2019/11/18\n",
      "2.4 1\n",
      "这天不存在着火点: 2019/11/19\n",
      "这天不存在着火点: 2019/11/20\n",
      "这天不存在着火点: 2019/11/21\n",
      "这天不存在着火点: 2019/11/22\n",
      "这天不存在着火点: 2019/11/23\n",
      "这天不存在着火点: 2019/11/24\n",
      "这天不存在着火点: 2019/11/25\n",
      "这天不存在着火点: 2019/11/26\n",
      "2019/11/27\n",
      "2.8 1\n",
      "2019/11/28\n",
      "2.5 2\n",
      "这天不存在着火点: 2019/11/29\n",
      "2019/11/30\n",
      "3.3 1\n",
      "这天不存在着火点: 2019/12/1\n",
      "这天不存在着火点: 2019/12/2\n",
      "这天不存在着火点: 2019/12/3\n",
      "这天不存在着火点: 2019/12/4\n",
      "这天不存在着火点: 2019/12/5\n",
      "这天不存在着火点: 2019/12/6\n",
      "这天不存在着火点: 2019/12/7\n",
      "2019/12/8\n",
      "4.4 2\n",
      "这天不存在着火点: 2019/12/9\n",
      "这天不存在着火点: 2019/12/10\n",
      "这天不存在着火点: 2019/12/11\n",
      "这天不存在着火点: 2019/12/12\n",
      "2019/12/13\n",
      "3.1 1\n",
      "这天不存在着火点: 2019/12/14\n",
      "这天不存在着火点: 2019/12/15\n",
      "这天不存在着火点: 2019/12/16\n",
      "这天不存在着火点: 2019/12/17\n",
      "这天不存在着火点: 2019/12/18\n",
      "这天不存在着火点: 2019/12/19\n",
      "2019/12/20\n",
      "14.1 5\n",
      "2019/12/21\n",
      "18.44043321299639 277\n",
      "2019/12/22\n",
      "16.881851851851852 270\n",
      "2019/12/23\n",
      "7.145689655172413 116\n",
      "2019/12/24\n",
      "5.0274193548387105 62\n",
      "2019/12/25\n",
      "8.2225 80\n",
      "2019/12/26\n",
      "6.551562499999999 64\n",
      "2019/12/27\n",
      "8.433333333333332 3\n",
      "2019/12/28\n",
      "2.7 1\n",
      "这天不存在着火点: 2019/12/29\n",
      "2019/12/30\n",
      "1.866666666666667 3\n",
      "2019/12/31\n",
      "12.848951048951049 143\n",
      "2020/1/1\n",
      "8.132196969696968 264\n",
      "2020/1/2\n",
      "10.041666666666666 336\n",
      "2020/1/3\n",
      "10.17867867867868 333\n",
      "这天不存在着火点: 2020/1/4\n",
      "这天不存在着火点: 2020/1/5\n",
      "2020/1/6\n",
      "1.1333333333333335 3\n",
      "这天不存在着火点: 2020/1/7\n"
     ]
    }
   ],
   "source": [
    "years = ['2019', '2020']\n",
    "mouths = ['10', '11', '12', '1']\n",
    "for y in years:\n",
    "    for m in mouths:\n",
    "        if m == '11' and y == '2019':\n",
    "            for d in range(1, 31):\n",
    "                try:\n",
    "                    num, day = ave_frp(data1, str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(num, day)\n",
    "                except KeyError:\n",
    "                    print(\"这天不存在着火点:\", str(y) + '/' + str(m) + '/' + str(d))\n",
    "                \n",
    "        if m == '1' and y == '2020':\n",
    "            for d in range(1, 8):\n",
    "                try:\n",
    "                    num, day = ave_frp(data1, str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(num, day)\n",
    "                except KeyError:\n",
    "                    print(\"这天不存在着火点:\", str(y) + '/' + str(m) + '/' + str(d))\n",
    "        \n",
    "        elif (m == '10' or m == '12') and y == '2019':\n",
    "            for d in range(1, 32):\n",
    "                try:\n",
    "                    num, day = ave_frp(data1, str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(str(y) + '/' + str(m) + '/' + str(d))\n",
    "                    print(num, day)\n",
    "                except KeyError:\n",
    "                    print(\"这天不存在着火点:\", str(y) + '/' + str(m) + '/' + str(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18.116666666666667 6\n"
     ]
    }
   ],
   "source": [
    "num, day = ave_frp(data1, '2019/10/22')\n",
    "print(num, day)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
